﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace ProjectQuaDep.Controls
{
    public partial class Top3ProductBot : System.Web.UI.UserControl
    {
        private string TOP = "3";
        private string sFormat = @" <li{4}><a href=""{0}"">
                        <img src=""{1}"" /></a>
                        <h4>
                            <a href=""{0}"">{2}</a></h4>
                        <p>
                            {3}
                        </p>
                        <a href=""{0}"">
                            <center><img src=""/images/datmua.png"" /></center></a> 
                    </li>";
        protected void Page_Load(object sender, EventArgs e)
        {
            DataTable dt = BO.ProductUserBO.ProductUBO.GetTopHomeFocusBO(TOP);
            if (dt != null && dt.Rows.Count > 0)
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    DataRow dr = dt.Rows[i];
                    string title = dr[BO.Const.tbProducts.Title].ToString();
                    string sapo = dr[BO.Const.tbProducts.Sapo].ToString();
                    string productID = dr[BO.Const.tbProducts.id].ToString();
                    string url = BO.ReWriteUrl.BuildLink.BuildLinkProduct(productID);
                    string Images = BO.Utils.CropImage(278, 275, BO.Utils.GetOneImagesByArr(dr[BO.Const.tbProducts.Avatar].ToString()));
                    ltProductsTop.Text += string.Format(sFormat, url, Images, title, sapo, (i + 1) % 3 == 0 ? " class=\"last\"" : "");
                }
            }
            else
            {
                this.Visible = false;
            }
            //
        }
    }
}